#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <windows.h>
#include <winbase.h>

#include <fstream>
#include <iostream>
#include <sstream>
#include <map>

#include "..\Driver\public.h"
#include "MyPacketProcessor\exports.h"

#include "DeviceInformation.h"
#include <devguid.h>

#include <cfgmgr32.h>
#include <tchar.h>
#include <stdio.h>
#include <setupapi.h>

#include <winioctl.h>

#include <QMessageBox>
#include <QMainWindow>
#include <QList>
#include <QAbstractTableModel>

#include "PacketInformationDialog.h"
#include "DeviceInformation.h"


#define SIZE_OF_PACKET 65536*2
#define MAX_HARDWARE_NAME_LEN 200

#ifndef GUID_DEVINTERFACE_USB_HUB
// http://msdn.microsoft.com/en-us/library/bb663109.aspx
const GUID GUID_DEVINTERFACE_USB_HUB = {0xf18a0e88, 0xc30c, 0x11d0, {0x88, 0x15, 0x00,	0xa0, 0xc9, 0x06, 0xbe, 0xd8}};  
#endif
#ifndef GUID_DEVINTERFACE_USB_DEVICE
// http://msdn.microsoft.com/en-us/library/bb663093.aspx
const GUID GUID_DEVINTERFACE_USB_DEVICE = {  0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed} };
#endif

#ifndef GUID_DEVINTERFACE_USB_HOST_CONTROLLER
// http://msdn.microsoft.com/en-us/library/bb663109.aspx
const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = {  0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27} };
#endif

DWORD WINAPI WorkerThread(LPVOID CompletionPortID);



typedef struct PACKET_
{
    OVERLAPPED Overlapped;
    char Buffer[SIZE_OF_PACKET];
    HANDLE Device;
	
	PACKET_ *pNext;
	PACKET_ *pPrev;

} PACKET, * PPACKET;

typedef struct _HANDLE_DATA
{
    int something;
} HANDLE_DATA, *PHANDLE_DATA;


extern HANDLE CompletionPort;

DWORD WINAPI PacketGeneratorThread(LPVOID lpParameter);

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;

    PacketInformationDialog *packInfDlg;
	QModelIndex deviceListIndex;

	QMenu *DeviceListenMenu;
	QAction *actionStartListenDevice;
	QAction *actionStopListenDevice;


	void EnumerateUsbDevices();
	//void MapDeviceVidsPids();

private slots:
    void on_tableView_doubleClicked(QModelIndex index);
    void on_stopButton_clicked();
    void on_startButton_clicked();
	void on_actionFilter_clicked();

	void ClearEventList_clicked();
	void RefreshEventList_clicked();
	void AddObserved_clicked();

	void DeviceContexMenuRequested(const QPoint &pos);
	void StartListenDeviceClicked();
	void StopListenDeviceClicked();
};

#endif // MAINWINDOW_H
